#include<bits/stdc++.h>
#define int long long 
using namespace std;

const int maxn=15;
vector<int> v;
string s, t;
int n, k;
int op[maxn], x[maxn], y[maxn];
bool flag;

void check(){
	string ss=s;
	for (int u: v) {
		int a=x[u], b=y[u];
		if(op[u]==1){
			ss[a]-='0';
			ss[a]=(ss[a]+b)%10;
			ss[a]+='0';
		} else {
			swap(ss[a], ss[b]);
		}
		if(ss==t){
			flag=true;
		}
	}
}

void solve(){
	cin>>n;
	cin>>s;
	cin>>t;
	cin>>k;
	for(int i=1;i<=k;i++){
		v.push_back(i);
		cin>>op[i]>>x[i]>>y[i];
	}
	
	while (next_permutation(v.begin(), v.end())) {
		check();
		if(flag){
			cout<<"Yes"<<'\n';
			return;
		}
	}
	cout<<"No"<<'\n';
}


signed main(){
	ios::sync_with_stdio(0), cin.tie(0),cout.tie(0);
	solve();
	return 0;
}
